package cate.game.play.fighter;

import cate.common.table.d.GDFight;
import cate.common.util.SplitParser;
import cate.game.play.base.PassiveBuffItem;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.turn.AppendTurn;
import cate.game.play.skill.Skill;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;


@NoteClass("英雄战斗者")
public class HeroFighter extends Fighter<HeroFighter> {

	@NoteField("英雄tid")
	public int heroTid;

	@NoteField("原型id")
	public int protoId;

	@NoteField("当前站位")
	public byte pos;

	@NoteField("星级")
	public int star;

	@NoteField("等级")
	public int level;

	@NoteField("职业")
	public byte job;

	@NoteField("阵营")
	public byte camp;

	@NoteField("是否死亡")
	protected boolean dead = false;

	@Override
	public byte getJob() {
		return job;
	}

	@Override
	public byte getCamp() { return camp; }

	@Override
	public void setPos(byte pos) { this.pos = pos; }

	@Override
	public byte getPos(){
		return pos;
	}

	@Override
	public int getLevel(){return level;}

	@Override
	public int getProtoId() {
		return protoId;
	}

	@Override
	public int getStar() { return star;}

	@Override
	public void setDead(boolean dead) {
		this.dead = dead;
	}

	public HeroFighter() {
		this.type = GDFight.Fighter.HERO;
	}


	@Override
	public boolean isDead(){
		return dead;
	}



	@Override
	public void readFrom(HeroFighter tar) {
		super.readFrom(tar);
		this.heroTid = tar.heroTid;
		this.protoId = tar.protoId;
		this.star = tar.star;
		this.pos = tar.pos;
		this.level = tar.level;
		this.camp = tar.camp;
		this.job = tar.job;
		this.dead = tar.dead;
	}


	@Override
	public HeroFighter copy() {
		HeroFighter cp = new HeroFighter();
		cp.readFrom(this);
		return cp;
	}


	@Override
	public void handleFirstEnter(ActionCtx action) {
		if (enter) {
			return;
		}
		enter = true;
		for (Integer teamBuff : getFightTeam().getTeamBuffs()) {
			buff.tryAddByTid(action, teamBuff);
		}
		for (Skill skill : this.skill.getAllSkill()) {
			//添加被动buff
			for (String code : skill.cfg.getPassiveBuffs()) {
				for (PassiveBuffItem item : SplitParser.parse(PassiveBuffItem.class, code)) {
					this.buff.tryAddSome(action, this, item.buffId, item.num);
				}
			}
			//处理开场技能
			if (skill.cfg.row.beginSkill > 0) {
				Skill beginSkill = action.getCfg().skill.buildById(skill.owner, skill.cfg.row.beginSkill);
				if (beginSkill != null) {
					action.getRound().addAppendTurn(new AppendTurn(skill.owner, beginSkill));
				}
			}
			//处理首次登场技能处理
			if (skill.passive != null) {
				skill.passive.onFirstEnter(action);
			}
		}
	}
}
